/*
 * @Description: 性别选择
 * @Author: iamsmiling
 * @Date: 2021-05-30 14:34:52
 * @LastEditTime: 2021-06-11 10:35:35
 */
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

enum Gender { female, male }

extension GenderKit on Gender {
  String get name => {Gender.male: "先生", Gender.female: "女士"}[this] ?? "";
}

Future<Gender?> showGenderPicker(BuildContext context) {
  return showCupertinoModalPopup<Gender?>(
      context: context,
      builder: (BuildContext context) {
        return Material(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(10),
              topRight: Radius.circular(10),
            ),
          ),
          child: Container(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                    margin: EdgeInsets.only(top: 24, bottom: 20),
                    child: Text(
                      "选择性别",
                      style: TextStyle(
                          fontSize: 14, color: const Color(0xFF666666)),
                    )),
                Divider(),
                GestureDetector(
                  onTap: () => Navigator.of(context).pop(Gender.male),
                  child: Container(
                      margin: EdgeInsets.symmetric(vertical: 16),
                      child: Text(
                        Gender.male.name,
                        style: TextStyle(
                            fontSize: 15, color: const Color(0xFF333333)),
                      )),
                ),
                Divider(),
                GestureDetector(
                  onTap: () => Navigator.of(context).pop(Gender.female),
                  child: Container(
                      margin: EdgeInsets.symmetric(vertical: 16),
                      child: Text(Gender.female.name,
                          style: TextStyle(
                              fontSize: 15, color: const Color(0xFF333333)))),
                ),
                GestureDetector(
                  onTap: Navigator.of(context).pop,
                  child: Container(
                      alignment: Alignment.center,
                      width: MediaQuery.of(context).size.width,
                      padding: EdgeInsets.symmetric(vertical: 13),
                      decoration: BoxDecoration(
                          color: const Color(0xFFF5F5F5),
                          borderRadius: BorderRadius.circular(20)),
                      margin: EdgeInsets.only(
                          top: 12, right: 18, left: 18, bottom: 18),
                      child: Text("取消",
                          style: TextStyle(
                              fontSize: 15, color: const Color(0xFF444444)))),
                ),
              ],
            ),
          ),
        );
      });
}
